package com.easymin.weixin.entity.area;

import org.apache.commons.collections.CollectionUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * 地区.
 *
 * @author Shine
 */
public class Area implements Serializable {

  private static final long serialVersionUID = 1L;

  private Long id;

  private Date created;

  private Date updated;

  private String name;// 地区名称

  private String memo;// 收费说明


  public Long getId() {
    return id;
  }

  public void setId(Long id) {
    this.id = id;
  }

  public Date getCreated() {
    return created;
  }

  public void setCreated(Date created) {
    this.created = created;
  }

  public Date getUpdated() {
    return updated;
  }

  public void setUpdated(Date updated) {
    this.updated = updated;
  }

  private List<ChargeStartTime> chargeStartTimes;

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public String getMemo() {
    return memo;
  }

  public void setMemo(String memo) {
    this.memo = memo;
  }

  public List<ChargeStartTime> getChargeStartTimes() {
    return chargeStartTimes;
  }

  public void setChargeStartTimes(List<ChargeStartTime> chargeStartTimes) {
    this.chargeStartTimes = chargeStartTimes;
  }
  
  /**
   * 筛选收费标准.
   */
  public void sortDistance() {
    if (CollectionUtils.isNotEmpty(chargeStartTimes)) {
      for (ChargeStartTime cst : chargeStartTimes) {
        if (CollectionUtils.isNotEmpty(cst.getChargeStartDistances())) {
          Collections.sort(cst.getChargeStartDistances(), new Comparator<ChargeStartDistance>() {
            public int compare(ChargeStartDistance arg0, ChargeStartDistance arg1) {
              return arg0.getId().compareTo(arg1.getId());
            }
          });
        }
      }
    }
  }

  @Override
  public String toString() {
    return "Area [name=" + name + ", memo=" + memo + ", chargeStartTimes=" + chargeStartTimes
        + ", id=" + id + "]";
  }


}
